package com.example.minio.controller;

import com.example.minio.util.MinioUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/minio")
public class MinioController {

    @Resource
    private MinioUtil minioUtil;

    @GetMapping("/isBucketExists")
    public String isBucketExists(String bucketName) {
        //如果bucketName不存在就创建
        minioUtil.existBucket(bucketName);
        return "bucket name is exists";
    }

    @GetMapping("/removeBucket")
    public String removeBucket(String bucketName) {
        //如果bucketName不存在就创建
        minioUtil.removeBucket(bucketName);
        return "bucket is remove";
    }

    @PostMapping("/upload")
    public String upload(MultipartFile file) {
        minioUtil.upload(new MultipartFile[]{file});
        return "upload success";
    }

}
